#ifndef Tui_TPage_h
#define Tui_TPage_h

#include "TMaskPanel.h"  
#include "TLabel.h"
#include "TButton.h"


class TPageBar:public TPanel{
public:
    TPageBar();
    CREATE_FUNC(TPageBar); 
    virtual bool init(); 
    virtual void setCurPage(int page);
    virtual void setTotalPage(int page);
};

class TPage:public TScrollPanel{
    
public:
    TPage();
    CREATE_FUNC(TPage);
    
    virtual bool init();
    
    void layout();
    
    static TPage*  create(xml_node<> * pItem); 
    virtual void  initWidthConf(xml_node<> * pItem); 
    
    
    virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
    virtual void ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent);
    
    int nCurPage; 
    int getTotalPage();
    int nMaxNum;
    
    virtual  void clearItems();
    
    void gotoPage(int );
    
    TPanelItem* getItemByIdx(int idx);
	TPanelItem* ensureItemByIdx(int idx);
    
    DEV_PROPERTY(TButton*, m_pLeftBtn, LeftBtn);
    DEV_PROPERTY(TButton*, m_pRightBtn, RightBtn);
    DEV_PROPERTY(TLabel*, m_pPageTxt,  PageTxt);
    DEV_PROPERTY(TPageBar*, m_pBar,  Bar);
protected:
    
    int m_nRowNum;
    int m_nColNum;
    int m_nRowDistance;
    int m_nColDistance;
    int m_nItemWidth;
    int m_nItemHeight; 
    
    void onPageEnd(); 
    float getPageWidth(); 
    float getPageHeight();
    string itemName;
    
};



#endif
